package com.ruoyi.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.shop.domain.TbCourseActivity;
import com.ruoyi.shop.service.ITbCourseActivityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 秒杀Controller
 * 
 * @author ruoyi
 * @date 2023-01-11
 */
@RestController
@RequestMapping("/activity")
@RefreshScope
public class TbCourseActivityController extends BaseController
{
    @Autowired
    private ITbCourseActivityService tbCourseActivityService;

    /**
     * 查询秒杀列表
     */
//    @RequiresPermissions("system:activity:list")
    @GetMapping("/list")
    public TableDataInfo list(TbCourseActivity tbCourseActivity)
    {
        startPage();
        List<TbCourseActivity> list = tbCourseActivityService.selectTbCourseActivityList(tbCourseActivity);
        return getDataTable(list);
    }

    /**
     * 导出秒杀列表
     */
//    @RequiresPermissions("system:activity:export")
    @Log(title = "秒杀", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCourseActivity tbCourseActivity)
    {
        List<TbCourseActivity> list = tbCourseActivityService.selectTbCourseActivityList(tbCourseActivity);
        ExcelUtil<TbCourseActivity> util = new ExcelUtil<TbCourseActivity>(TbCourseActivity.class);
        util.exportExcel(response, list, "秒杀数据");
    }

    /**
     * 获取秒杀详细信息
     */
//    @RequiresPermissions("system:activity:query")
    @GetMapping(value = "/getActivity/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Integer activityId)
    {
        return success(tbCourseActivityService.selectTbCourseActivityByActivityId(activityId));
    }

    /**
     * 新增秒杀
     */
//    @RequiresPermissions("system:activity:add")
    @Log(title = "秒杀", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TbCourseActivity tbCourseActivity)
    {
        return toAjax(tbCourseActivityService.insertTbCourseActivity(tbCourseActivity));
    }

    /**
     * 修改秒杀
     */
//    @RequiresPermissions("system:activity:edit")
    @Log(title = "秒杀", businessType = BusinessType.UPDATE)
    @PutMapping("/updata")
    public AjaxResult edit(@RequestBody TbCourseActivity tbCourseActivity)
    {
        return toAjax(tbCourseActivityService.updateTbCourseActivity(tbCourseActivity));
    }

    /**
     * 删除秒杀
     */
//    @RequiresPermissions("system:activity:remove")
    @Log(title = "秒杀", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete/{activityIds}")
    public AjaxResult remove(@PathVariable Integer[] activityIds)
    {
        return toAjax(tbCourseActivityService.deleteTbCourseActivityByActivityIds(activityIds));
    }
}
